$package('itsm.system');

itsm.system.ruleMain=function(){
	this.opt='';
	return {
		//列表
		ruleMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'rule!findRulePager.action',
				caption:'规则管理',
				colNames:['ID','规则名称','规则代码','规则值','备注'],
			 	colModel:[
			 	          {name:'ruleId',align:'center'},
			 	          {name:'ruleName',align:'center'},
			 	          {name:'ruleCode',align:'center'},
			 	          {name:'ruleValue',align:'center'},
			 	          {name:'remark',align:'left'}
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "ruleId"}),
				sortname:'ruleId',
				pager:'#ruleMainPager'
				});
				$("#ruleMainGrid").jqGrid(params);
				$("#ruleMainGrid").navGrid('#ruleMainPager',navGridParams);
				//列表操作项
				$("#t_ruleMainGrid").css(jqGridTopStyles);
				$("#t_ruleMainGrid").html($('#ruleMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#ruleMainGrid","regCenter",10);
		},
		//打开添加窗口
		openAddWin:function(){
			opt='saveRule';
			resetForm('#ruleMain_add_form');
			$('#ruleMain_add_win').window('open');
		},
		
		//打开编辑窗口
		openEditWin:function(){
			opt='editRule';
			checkBeforeEditGrid('#ruleMainGrid',function(rowData){
				$.post('rule!findRuleByRuleCode.action','ruleDTO.ruleCode='+rowData.ruleCode,function(data){
					$('#ruleMain_ruleId').val(data.ruleId);
					$('#ruleMain_ruleName').val(data.ruleName);
					$('#ruleMain_ruleCode').val(data.ruleCode);
					$('#ruleMain_ruleValue').val(data.ruleValue);
					$('#ruleMain_remark').val(data.remark);
				});
				$('#ruleMain_add_win').window('open');
			});	
		},
		
		//保存
		saveRule:function(){
			if($('#ruleMain_add_win').form('validate')){
				var _param = $('#ruleMain_add_win form').serialize();
				$.post('rule!'+opt+'.action',_param,function(data){
					msgShow('保存成功!','show');
					$('#ruleMain_add_win').window('close');
					$('#ruleMainGrid').trigger('reloadGrid');
				})
				
			}
		},
		//删除
		deleteRule:function(){
			checkBeforeDeleteGrid('#ruleMainGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("rule!deleteRule.action", pp, function(){
					$('#ruleMainGrid').trigger('reloadGrid');
					msgShow('删除成功!','show');
				}, "json");
			});
		},
		//打开搜索窗口
		openSearchWin:function(){
			$('#ruleMain_search_win').window('open');
		},
		//搜索
		searchRule:function(){
			var sdata=$('#ruleMain_search_win form').getForm();
			var postData = $("#ruleMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'rule!findRulePager.action';
			$('#ruleMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		init:function(){
			itsm.system.ruleMain.ruleMainGrid();
		}
	}
	
}();

$(function(){
	itsm.system.ruleMain.init();
});